<?php
session_start();

include('../classes/autoloading_pages.include.php');
if (isset($_SESSION['logged'])) {
    header('Location: /eventijesolo/');
    exit();
} else if (isset($_POST['submit'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $remember_me = (isset($_POST['remember-me'])) ? true : false;
    $um = new UsersManager();
    $user = $um->login($username, $password);
    if ($user) {
        $_SESSION['logged'] = 1;
        $_SESSION['user'] = $user->username;
        if($remember_me) {
            if($um->save_cookie($user->username)) {
            } else {
            }
        }
        header("Location: /eventijesolo/");
        exit();
    } else {
        $_SESSION['login_error'] = 1;
        header("Location: /eventijesolo/login/");
        exit();
    }
}

include('login.view.php');
?>
